﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.UserCon.Locomotive.TrainRepair.Work.Fittings
{
    public partial class uc_Locomotive_TrainRepair_Work_Fittings_DownTrain_AddNewCode : DevExpress.XtraEditors.XtraForm
    {
        public string _FTID = "";
        public string _FTName = "";
        public string _TDID = "";
        public string _TDName = "";
        public string _State = "";

        public uc_Locomotive_TrainRepair_Work_Fittings_DownTrain_AddNewCode()
        {
            InitializeComponent();
        }

        private void uc_Locomotive_TrainRepair_Work_Fittings_DownTrain_AddNewCode_Load(object sender, EventArgs e)
        {
            LoadTrainList();
        }
        private void LoadTrainList()
        {
            string strSQL = "select f_code as f_name,f_id,f_fcdate,f_indate from TS_TR_B_Loco_Fittings_Base_List where f_typeid=" + _FTID + " and f_del=0 order by f_name asc";
            DataTable _dt = new DataTable();
            TS_Win_Class.FilledDataTable(strSQL,_dt);
            gc_Info.DataSource = _dt;
        }

        private void bt_Add_Click(object sender, EventArgs e)
        {
            string _f_type = "";
            if (_State == "0")
            {
                _f_type = "1";
            }
            else
            {
                _f_type = "2";
            }
            if (tb_Name.Text.Trim().Length <1 || de_Date.Text.Trim().Length<10)
            {
                MessageBox.Show("编号或日期格式不正确！");
            }
            else
            {
                if (TS_Win_Class.GetSQlFieldValue("select count(*) as f_count from TS_TR_B_Loco_Fittings_Base_List where f_del=0 and f_code='" + tb_Name.Text.Trim() + "' and f_typeid=" + _FTID + " and f_del=0", "f_count") == "0")
                {
                    string strSQL= "insert into TS_TR_B_Loco_Fittings_Base_List(f_code,f_typeid,f_tdid,f_workerid,f_fcdate,f_type) values('" + tb_Name.Text.Trim() + "'," + _FTID + ",'" + _TDID + "',"+TS_Win_Locomotive_MainForm.pUserInfoMain.GuId+",'"+de_Date.Text.Trim()+"',"+_f_type+")";
                    string _ID = TS_Win_Class.MySqlComGetID(strSQL);
                    strSQL = "update TS_TR_B_Loco_Fittings_Base_List set f_indate=dateadd(day,(select f_indate from TS_S_T_P_TrainDepSys where f_id=TS_TR_B_Loco_Fittings_Base_List.f_tdid),f_fcdate) where f_id=" + _ID;
                    TS_Win_Class.MySqlCom(strSQL);
                    LoadTrainList();
                }
                else
                {
                    MessageBox.Show("该配件编号已存在！");
                }
            }
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
    }
}